home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 26.zip / BS1 part 26 / C for beginners.adf / source / pixel.c < prev    next >
C/C++ Source or Header  |  1978-01-17  |  2KB  |  92 lines

  1. /* pixel.c 25.4.6             */
  2. /* From Amiga C for Beginners */
  3. /* by Abacus                  */
  4.  
  5. #include <exec/types.h>
  6. #include <intuition/intuition.h>
  7.  
  8. extern struct Window *OpenWindow(); /* Declaration */
  9. extern long *OpenLibrary();  /* Hello Aztec-User! */
  10. extern double sin();
  11.  
  12. struct IntuitionBase *IntuitionBase;
  13. struct GfxBase *GfxBase; 
  14.  
  15. #define INTUITION_REV 0
  16. #define GRAPHICS_REV 0
  17.  
  18. /* Number of colors of Workbench */
  19. #define WB_COLORS 4
  20.  
  21. struct NewWindow NewWindow =
  22. {
  23.    10, 50,   /* X and Y Position */
  24.    360, 120, /* Width, Height */
  25.    3, 2,     /* Color Indexes */
  26.    NULL,
  27.    SMART_REFRESH | ACTIVATE | WINDOWDRAG | WINDOWDEPTH,
  28.    NULL,
  29.    NULL,
  30.    "This Line is changed!",
  31.    NULL,
  32.    NULL,
  33.    0, 0,
  34.    640, 200, /* PAL users - change 200 to 256 */
  35.    WBENCHSCREEN
  36. };
  37.  
  38.  
  39. main()
  40. {
  41.    struct Window *Window;
  42.    register struct RastPort *r;
  43.    register int i, j, top, yoffset;
  44.    int i_to, j_to, color, colors[512];
  45.    double factor;
  46.  
  47.    if((IntuitionBase = (struct IntuitionBase *)
  48.      OpenLibrary("intuition.library", INTUITION_REV))
  49.       == NULL)
  50.      exit(FALSE);
  51.  
  52.    if((GfxBase = (struct GfxBase *)
  53.      OpenLibrary("graphics.library", GRAPHICS_REV) )
  54.        == NULL)
  55.       exit(FALSE);
  56.  
  57.    if((Window = OpenWindow(&NewWindow)) == NULL)
  58.      exit (FALSE);
  59.  
  60.    r = Window->RPort;
  61.    top = Window->Height / 4;
  62.    factor = 2 * 3.1415926 / Window->Width * 1.5;
  63.      /* 1.5 Sine Waves */
  64.  
  65.    for(i = 2, i_to = Window->Width - 2; i < i_to; i++)
  66.      {
  67.         for(j = 0; j < top; j++) /* A vertical line */
  68.           {         /* Transfer to Array */
  69.                color = ReadPixel(r, i, j);
  70.                if(++color == WB_COLORS)
  71.                   colors[j] = 0;
  72.                else
  73.                   colors[j] = color;
  74.                   /* increase color index by one */
  75.          }
  76.         for(j = 0,
  77.            yoffset = top + top * sin(factor * i) + 16;
  78.            j < top; j++)
  79.            if(colors[j])  /* If Pixel should be set */
  80.              {
  81.                 SetAPen(r, colors[j]);
  82.                 WritePixel(r, i, j + yoffset);
  83.              }
  84.      }
  85.    Delay(1500);    /* Wait 1500 Ticks = 30 seconds */
  86.    CloseWindow(Window);
  87.    CloseLibrary(GfxBase);
  88.    CloseLibrary(IntuitionBase);
  89.    exit(TRUE);
  90. }
  91.  
  92.